export default {
    mounted(el: any, binding: any) {
        const copy = function () {
            console.log(binding);
            let value = binding.value;
            let success = binding.arg;
            if (navigator.clipboard) {
                navigator.clipboard.writeText(value).then(() => {
                    success && success(value);
                });
            } else {
                const input = document.createElement("input") as HTMLInputElement;
                input.readOnly = true;
                input.style.position = "fixed";
                input.style.top = "-99999px";
                input.value = value;
                document.body.appendChild(input);
                input.select();
                const res = document.execCommand("Copy");
                res && success && success(value);
                document.body.removeChild(input);
            }
        };
        el.addEventListener("click", copy);
    },
    beforeUnmount(el: HTMLElement) {
        el.removeEventListener("click", () => {});
    }
};
